| Total Complexity | 2 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 17 | |||
| 18 | @Controller('tasks') |
||
| 19 | @ApiTags('Task') |
||
| 20 | @ApiBearerAuth() |
||
| 21 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
| 22 | export class CreateTaskAction { |
||
| 23 | constructor( |
||
| 24 | @Inject('ICommandBus') |
||
| 25 | private readonly commandBus: ICommandBus |
||
| 26 | ) {} |
||
| 27 | |||
| 28 | @Post() |
||
| 29 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
| 30 | @ApiOperation({summary: 'Create new task'}) |
||
| 31 | public async index(@Body() taskDto: TaskDTO) { |
||
| 32 | try { |
||
| 33 | const id = await this.commandBus.execute( |
||
| 34 | new CreateTaskCommand(taskDto.name) |
||
| 35 | ); |
||
| 36 | |||
| 37 | return {id}; |
||
| 38 | } catch (e) { |
||
| 39 | throw new BadRequestException(e.message); |
||
| 40 | } |
||
| 43 |